<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象</title>
    <script>
        // 创建对象方式一：new Object()
        let obj01 = new Object();

        // 给对象设置属性（写）
        obj01.weaponName = "AK47";
        obj01.weaponPrice = 1000;
        obj01.weaponWeight = 1.5;

        // 给对象设置属性（读）
        console.log(obj01.weaponName);
        console.log(obj01.weaponPrice);
        console.log(obj01.weaponWeight);

        // 创建对象方式二：{}
        let obj02 = {
            carName: "问界",
            carPrice: 1000000,
            carWeight: 1.5
        };
        obj02.carColor = "红色";
        console.log(obj02);

        // this 关键词
        let testThisObj01 = {
            objName:"name 01",
            myShowName: function () {
                console.log(this.objName)
            }
        };
        let testThisObj02 = {
            objName:"name 02",
            myShowName: function () {
                console.log(this.objName)
            }
        };

        function printName() {
            // this 指向调用当前函数的对象
            console.log(this.objName);
        }

        testThisObj01.showName = printName;
        testThisObj02.showName = printName;

        // 对象 1 调用方法，this 指向对象 1
        testThisObj01.showName();

        // 对象 2 调用方法，this 指向对象 2
        testThisObj02.showName();

        testThisObj01.myShowName();
        testThisObj02.myShowName();
    </script>
</head>
<body>

</body>
</html>